package com.wen.task.customTask;

import com.wen.config.DefaultPropertyConfig;
import com.wen.moudle.Account;
import com.wen.task.AbstractTask;
import com.wen.utils.AccountManager;
import com.wen.utils.ConsoleUtils;

import java.util.List;

public class CustomFavoriteProperties extends AbstractTask {

    public CustomFavoriteProperties(Account account) {
        super(account);
    }

    @Override
    public void run() {
        List<String> keywords = account.getDefaultPropertyConfig().getKeywords();
        outer: while (true){
            System.out.println("0、查看当前属性");
            System.out.println("1、添加属性");
            System.out.println("2、删除属性");
            System.out.println("3、恢复默认属性");
            System.out.println("4、清空所有属性");
            System.out.println("5、保存并退出");
            ConsoleUtils.printName(account);
            int input = ConsoleUtils.inputNumber(0,5);
            switch (input){
                case 0:
                    System.out.println("你当前的已经定义的属性的白名单如下");
                    ConsoleUtils.printList(keywords);
                    break;
                case 1:
                    System.out.println("请输入要加入白名单的属性名称");
                    String line = ConsoleUtils.inputLine();
                    keywords.add(line);
                    System.out.println("添加成功");
                    break;
                case 2:
                    ConsoleUtils.printList(keywords);
                    System.out.println("请输入要删除的属性序号");
                    int ret = ConsoleUtils.inputNumber(0,keywords.size()-1);
                    keywords.remove(keywords.remove(ret));
                    System.out.println("删除成功");
                    break;
                case 3:
                    account.setDefaultPropertyConfig(new DefaultPropertyConfig());
                    keywords = account.getDefaultPropertyConfig().getKeywords();
                    System.out.println("重置成功");
                    break;
                case 4:
                    keywords.clear();
                    System.out.println("清除成功");
                    break;
                case 5:
                    AccountManager.saveAccount(account);
                    System.out.println("保存成功");
                    break outer;

            }

        }
    }

    @Override
    public String getTitle() {
        return "自定义属性过滤器";
    }
}
